import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TCPClient {

    public static void main(String[] args) {
        String serverAddress = "192.168.0.200"; // 服务器地址
        int port = 9096; // 服务器端口号

        try (Socket socket = new Socket(serverAddress, port)) {
            System.out.println("已连接到服务器");

            // 创建输入输出流
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

            // 向服务器发送数据
            String message = "Hello, Server!";
            out.println(message);
            System.out.println("已发送消息: " + message);

            // 接收服务器的响应
            String serverResponse = in.readLine();
            System.out.println("收到服务器响应: " + serverResponse);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}